﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using Data;

public partial class integral_my : System.Web.UI.Page
{
    protected int i = ReadRequest.RequestInt("i");
    protected int type = ReadRequest.RequestInt("type");
    protected Model.CMember modelcm = null;
    protected Model.UsersAccount uaccout = null;
    protected List<Model.IntegralExchange> userOrder = null;
    protected DataTable dt = null;
    protected void Page_Load(object sender, EventArgs e)
    {

        userLogin();
        bindData();

        StringBuilder sbrSQL = new StringBuilder();
        sbrSQL.Append(" select  sum(case when Type=1 then UseIntegral end) as huode,");
        sbrSQL.Append(" SUM(case when Type=2 then UseIntegral end)as xiaofei");
        sbrSQL.Append(" from IntegralExchange where datediff(MONTH,Addtime,getdate())=0 and ");
        sbrSQL.Append(" UserId=" + modelcm.Id + ""); 
        dt = new DataAccess().GetDataTable<Data.TInsert_Max>(sbrSQL.ToString());
        if (dt.Rows.Count == 0)
        {
            DataRow dr = dt.NewRow();
            dr["huode"] = 0;
            dr["xiaofei"] = 0; 
            dt.Rows.Add(dr);
            dt.AcceptChanges();

        }
    }
    protected void userLogin()
    {
        modelcm = BLL.CMember.UserLoginInfo();
        if (modelcm == null)
        {
            Response.Redirect("/Login.aspx");
        }
        else
        {
            uaccout = BLL.UsersAccount.GetModeluser_id(modelcm.Id);
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    { 
        bindData();
    }
    protected void timesl_SelectedIndexChanged(object sender, EventArgs e)
    { 
        bindData();
    }
    protected void bindData()
    {
        PagedDataSource pds = new PagedDataSource();
        int times = int.Parse(this.timesl.SelectedValue.ToString());
        string where = "";
        if (times == 0)
        {
            where = " and DateDiff(dd,Addtime,getdate())=0";
        }
        else if (times == 1)
        {
            where = " and datediff(month,Addtime,getdate())=0";
        }
        else if (times == 2)
        {
            where = " and datediff(week,Addtime,getdate())=0 ";
        }
        else if (times == 3)
        {
            where = " and datediff(Month,Addtime,getdate()) <=3 and datediff(Month,Addtime,getdate()) >=0";
        }
        else if (times == 4)
        {
            where = " and datediff(Month,Addtime,getdate()) <=6 and datediff(Month,Addtime,getdate()) >=0";
        }
        else
        {
            where = "";
        }
        if (type == 0)
        {
            type = 2;
        }
        string sql = "UserId=" + modelcm.Id + " and Type=" + type + " " + where;
        int totalCount = 0;
        userOrder = BLL.IntegralExchange.GetPageListBysql(this.AspNetPager1.CurrentPageIndex - 1, this.AspNetPager1.PageSize, sql, out totalCount);
        if (userOrder != null && userOrder.Count > 0)
        {

            AspNetPager1.RecordCount = totalCount;
            pds.AllowPaging = true;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;

        }
    }
}